package com.hee.erp.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hee.erp.modules.entity.BusCustomer2User;
import com.hee.erp.modules.entity.SysUser;
import com.hee.erp.modules.mapper.BusCustomer2UserMapper;
import com.hee.erp.modules.service.IBusCustomer2UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hee.erp.modules.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author weizehong
 * @since 2022-04-16
 */
@Service
@Transactional
public class BusCustomer2UserServiceImpl extends ServiceImpl<BusCustomer2UserMapper, BusCustomer2User> implements IBusCustomer2UserService {

    @Autowired
    ISysUserService userService;
    @Override
    public List<BusCustomer2User> getListByCustomerId(String customerId) {

        LambdaQueryWrapper<BusCustomer2User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BusCustomer2User::getCustomerId,customerId);
        List<BusCustomer2User> list = this.list(queryWrapper);
        for (BusCustomer2User customer2User : list) {
            SysUser user = userService.getById(customer2User.getUserId());
            customer2User.setUserName(user.getUserName());
        }
        return list;
    }

    @Override
    public List<String> listCustomerIdByUserIds(List<String> userIds) {

        LambdaQueryWrapper<BusCustomer2User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(BusCustomer2User::getUserId,userIds);
        List<BusCustomer2User> list = this.list(queryWrapper);
        List<String> customerIds = list.stream().map(BusCustomer2User::getCustomerId).collect(java.util.stream.Collectors.toList());
        return customerIds;
    }

    @Override
    public List<String> listCustomerIdsByUserId(String managerId) {

        LambdaQueryWrapper<BusCustomer2User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BusCustomer2User::getUserId,managerId);
        List<BusCustomer2User> list = this.list(queryWrapper);
        List<String> customerIds = list.stream().map(BusCustomer2User::getCustomerId).collect(java.util.stream.Collectors.toList());
        return customerIds;
    }
}
